<?php

namespace App\model;

use support\App;

class GuildTask
{
    const CUR_TABLE = '公会任务表.json';
    public static $items = null;

    /***
     * 获取物品表
     * @return array|null
     */
    public static function getItems()
    {
        if (!is_null(self::$items)) {
            return self::$items;
        }
        $path = app_path() . '/tables/' . self::CUR_TABLE;
        $file_content = file_get_contents($path);
        $file_content = json_decode($file_content, true);

        $arrs = $file_content['table_data']['data'];
        $keys = array_shift($arrs);
        $column_types = array_shift($arrs);
        $temp_data = [];
        foreach ($arrs as $index => $items) {
            $temp_arr = [];
            foreach ($items as $key => $item) {
                $temp_arr[$keys[$key]] = $item;
            }
            $temp_data[] = $temp_arr;
        }
        $temp_data = array_column($temp_data, null, 'key');
        self::$items = $temp_data;
        return $temp_data;
    }

    public static function getSingleByKey($item_key)
    {
        $items = self::getItems();
        return $items[$item_key] ?? [];
    }
}
